<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class SharesController extends AppController {

    var $layout = 'subpage';
    var $uses = array(
        'Share', 'Catshare', 'Basket', 'Game', 'Logo', 'Banner'
    );
    var $helpers = array('Cache');
    var $cacheAction = array(
        'index' => 120,
        'cat_shares' => 120
    );

    function index($page = 1) {
        $this->set('title_for_layout', 'Mách nhỏ cho bạn  - trái cây việt | trái cây viêt nam | trái cây ngoại nhập | trái cây | giỏ trái cây | trái cây tươi');
        $page = array_key_exists('page', $this->params['named']) ? $this->params['named']['page'] : $page;
        $conditions = array(
            'Share.published' => 1,
        );
        $this->paginate = array(
            'fields' => array('Share.id, Share.title, Share.alias, Share.intro,Share.images_small', "DATE_FORMAT(`Share`.`created`, '%d %m %Y') AS 'created'"),
            'conditions' => $conditions,
            'limit' => Configure::read('limit_list'),
            'order' => array(
                'Share.id' => 'DESC'
            ),
        );
        $data = $this->paginate('Share');
        $this->set('total', $this->params['paging']['Share']['count']);
        $this->set('data', $data);
        $this->set('cat_list', $this->Catshare->getListAll());
        $this->set('best_buy_product', $this->Basket->getBestBuy());
        $this->set('limit_page', $this->paginate['limit']);
        $this->set('content_image_url_path', Configure::read('content_image_url_path'));
        $this->set('basket_image_thumb_url_path', Configure::read('basket_image_thumb_url_path'));
        $this->set('lastestShare', $this->Share->getLastestShare());
        $this->set('game_image_thumb_url_path', Configure::read('game_image_thumb_url_path'));
        $this->set('logo', $this->Logo->getLogo());
        $this->set('banners_customers', $this->Banner->getBanners());
        $this->set('banner_image_thumb_url_path', Configure::read('banner_image_thumb_url_path'));
        $this->set('logo_thumb_url_path', Configure::read('logo_thumb_url_path'));
        $this->set('top_games', $this->Game->getTopGame());
        $this->set('start_page', $page);
    }

    function cat_shares($id, $slug) {
        $this->set('title_for_layout', 'Mách nhỏ cho bạn  - trái cây việt | trái cây viêt nam | trái cây ngoại nhập | trái cây | giỏ trái cây | trái cây tươi');
        $page = array_key_exists('page', $this->params['named']) ? $this->params['named']['page'] : 1;
        $conditions = array(
            'Share.published' => 1,
            'Share.cat_id' => $id
        );
        $this->paginate = array(
            'fields' => array('Share.id, Share.title, Share.alias, Share.intro,Share.images_small', "DATE_FORMAT(`Share`.`created`, '%d %m %Y') AS 'created'"),
            'conditions' => $conditions,
            'limit' => Configure::read('limit_list'),
            'order' => array(
                'Share.id' => 'DESC'
            ),
        );
        $data = $this->paginate('Share');
        $this->set('total', $this->params['paging']['Share']['count']);
        $this->set('data', $data);
        $this->set('cat_list', $this->Catshare->getListAll());
        $this->set('limit_page', $this->paginate['limit']);
        $this->set('best_buy_product', $this->Basket->getBestBuy());
        $this->set('content_image_url_path', Configure::read('content_image_url_path'));
        $this->set('basket_image_thumb_url_path', Configure::read('basket_image_thumb_url_path'));
        $this->set('game_image_thumb_url_path', Configure::read('game_image_thumb_url_path'));
        $this->set('logo', $this->Logo->getLogo());
        $this->set('banners_customers', $this->Banner->getBanners());
        $this->set('banner_image_thumb_url_path', Configure::read('banner_image_thumb_url_path'));
        $this->set('logo_thumb_url_path', Configure::read('logo_thumb_url_path'));
        $this->set('lastestShare', $this->Share->getLastestShare());
        $this->set('top_games', $this->Game->getTopGame());
        $this->set('start_page', $page);
    }

    function detail($id) {

        $content = $this->Share->read(array('id', 'title', 'content', 'cat_id'), $id);
        $this->set('title_for_layout', "Mách Nhỏ &gt;&gt;{$content['Share']['title']}- trái cây việt | trái cây viêt nam | trái cây ngoại nhập | trái cây | giỏ trái cây | trái cây tươi");
        $this->set('content', $content);

        $this->set('lastestShare', $this->Share->getLastestShare());
        $this->set('game_image_thumb_url_path', Configure::read('game_image_thumb_url_path'));
        $this->set('top_games', $this->Game->getTopGame());
        $this->set('cat_list', $this->Catshare->getListAllToArray());
        $this->set('other_shares', $this->Share->otherShare($id, $content['Share']['cat_id']));
        $this->set('best_buy_product', $this->Basket->getBestBuy());
        $this->set('basket_image_thumb_url_path', Configure::read('basket_image_thumb_url_path'));
        $this->set('logo', $this->Logo->getLogo());
        $this->set('banners_customers', $this->Banner->getBanners());
        $this->set('banner_image_thumb_url_path', Configure::read('banner_image_thumb_url_path'));
        $this->set('logo_thumb_url_path', Configure::read('logo_thumb_url_path'));
    }

}

?>
